package com.jiashihui.schema_lgorithm.schema.state;

/**
 * @author jiashihui
 * @describe: 状态模式的切换类
 * @date 2019/03/14
 */
public class QQContext {
    /* 上线状态 */
    private static final String ONLINE = "online";

    /* 离线状态 */
    private static final String OFFLINE = "offline";

    /* 状态 */
    private State state;

    public QQContext(State state) {
        this.state = state;
    }

    /**
     * 切换状态
     *
     * @author jiashihui
     */
    public void switchStatus() {
        String stateValue = state.getValue();
        if (ONLINE.equals(stateValue)) {
            state.online();
        } else if (OFFLINE.equals(stateValue)) {
            state.offline();
        }
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }
}
